﻿using AdminBase.Model;

namespace AdminBase.Common.Helpers
{
    /// <summary>
    /// 模型帮助类
    /// </summary>
    public static class EntityHelper
    {
        /// <summary>
        /// 新增时给字段赋值：是否删除/创建时间/修改时间
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static T SetAddValues<T>(T entity) where T : EntityCommon
        {
            entity.IsDeleted = false;
            entity.CreateDateTime = DateTime.Now;
            entity.UpdateDateTime = DateTime.Now;
            return entity;
        }

        /// <summary>
        /// 编辑时给字段赋值：修改时间
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static T SetEditValues<T>(T entity) where T : EntityCommon
        {
            entity.UpdateDateTime = DateTime.Now;
            return entity;
        }
    }
}
